package com.study.Util;

import com.github.pagehelper.Page;

import java.util.List;

public class PageUtil {

    public static <T> PageList setPageList(List<T> list,Integer pageNo,Integer pageSize){
        PageList pageList = new PageList();

        pageList.setPageElement(list);
        pageList.setPageNo(pageNo);
        pageList.setPageSize(pageSize);
        if(list instanceof Page){
           Page page = (Page)list;
           pageList.setTotalCount(Long.bitCount(page.getTotal()));
        }else {
            pageList.setTotalCount(list.size());
        }
        pageList.setTotalPage((int) Math.ceil((double) pageList.getTotalCount() / pageList.getPageSize()));
        return pageList;
    }

}
